{% extends "base.html" %}

{% block breadcrumb_current %}
    公共参数  > 用户列表 > 编辑用户
{% endblock %}
{% block content %}

    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        {% endfor %}
    {% endif %}
    
    <div class="bg-light p-3 shadow-sm">
        <h5 style="color: #417690;">
            编辑用户
            <a href="{% url 'user_list' %}" class="btn btn-secondary btn-sm float-end" style="margin-left: 15px;">返回用户列表</a></h5>
    </div>


<div class="container" style="margin-top: 50px;">
    <div class="card">
        <div class="card-body">
            <form method="post">

                {% csrf_token %}

        <div class="form-section" style="margin-top: 20px;">
            <h4 class="mb-3">基础信息</h4>                
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <label for="{{ form.realname.id_for_label }}" class="form-label">姓名</label>
                            <input type="text" name="{{ form.realname.name }}" id="{{ form.realname.id_for_label }}"
                                   class="form-control {% if form.realname.errors %}is-invalid{% endif %}"
                                   value="{{ form.realname.value|default:'' }}">
                            {% if form.realname.errors %}
                                <div class="invalid-feedback">{{ form.realname.errors|join:", " }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-4 mb-3">
                            <label for="{{ form.phone_number.id_for_label }}" class="form-label">电话</label>
                            <input type="text" name="{{ form.phone_number.name }}" id="{{ form.phone_number.id_for_label }}"
                                   class="form-control {% if form.phone_number.errors %}is-invalid{% endif %}"
                                   value="{{ form.phone_number.value|default:'' }}">
                            {% if form.phone_number.errors %}
                                <div class="invalid-feedback">{{ form.phone_number.errors|join:", " }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-4 mb-3">
                            <label for="{{ form.department.id_for_label }}" class="form-label">部门</label>
                            <select name="{{ form.department.name }}" id="{{ form.department.id_for_label }}"
                                    class="form-select {% if form.department.errors %}is-invalid{% endif %}">
                                {% for value, label in form.department.field.choices %}
                                    <option value="{{ value }}" {% if form.department.value == value %}selected{% endif %}>{{ label }}</option>
                                {% endfor %}
                            </select>
                            {% if form.department.errors %}
                                <div class="invalid-feedback">{{ form.department.errors|join:", " }}</div>
                            {% endif %}
                        </div>                    </div>
                    <div class="form-section" style="margin-top: 20px;">
                        <h4 class="mb-3">权限设置</h4>
                        <div class="row">
                            <div class="col-md-2 mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="{{ form.is_broad.name }}" id="{{ form.is_broad.id_for_label }}" 
                                           class="form-check-input {% if form.is_broad.errors %}is-invalid{% endif %}"
                                           {% if form.is_broad.value %}checked{% endif %}>
                                    <label for="{{ form.is_broad.id_for_label }}" class="form-check-label">
                                        管理所有县区
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-2 mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="{{ form.is_approver.name }}" id="{{ form.is_approver.id_for_label }}" 
                                           class="form-check-input {% if form.is_approver.errors %}is-invalid{% endif %}"
                                           {% if form.is_approver.value %}checked{% endif %}>
                                    <label for="{{ form.is_approver.id_for_label }}" class="form-check-label">
                                        赋予审批权限
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-2 mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="{{ form.is_deviceoperator.name }}" id="{{ form.is_deviceoperator.id_for_label }}" 
                                           class="form-check-input {% if form.is_deviceoperator.errors %}is-invalid{% endif %}"
                                           {% if form.is_deviceoperator.value %}checked{% endif %}>
                                    <label for="{{ form.is_deviceoperator.id_for_label }}" class="form-check-label">
                                        赋予设备操作权限
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-2 mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="{{ form.is_inventoryoperator.name }}" id="{{ form.is_inventoryoperator.id_for_label }}" 
                                           class="form-check-input {% if form.is_inventoryoperator.errors %}is-invalid{% endif %}"
                                           {% if form.is_inventoryoperator.value %}checked{% endif %}>
                                    <label for="{{ form.is_inventoryoperator.id_for_label }}" class="form-check-label">
                                        赋予物料操作权限
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-2 mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="{{ form.can_add_device.name }}" id="{{ form.can_add_device.id_for_label }}" 
                                           class="form-check-input {% if form.can_add_device.errors %}is-invalid{% endif %}"
                                           {% if form.can_add_device.value %}checked{% endif %}>
                                    <label for="{{ form.can_add_device.id_for_label }}" class="form-check-label">
                                        赋予增加设备权限
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="margin-top: 40px;">
                    <div class="col-md-12 text-center">
                        <button type="submit" class="btn ms-2" style="background-color: #417690; color: white;">保 存</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}